package com.ruoyi.framework.web.exception;

import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.BaseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器(处理业务异常)
 * 如果时出现404的话，是不被GlobalExceptionHandler处理的
 * @author ruoyi
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);


    /**
     * 处理非业务异常，比如 连接异常，空指针异常...
     *
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public AjaxResult runtimeException(Exception e) {
        return AjaxResult.error(HttpStatus.InnerError.getCode(), HttpStatus.InnerError.getMessage());
    }

    /**
     * 基础异常
     */
    @ExceptionHandler(BaseException.class)
    public AjaxResult baseException(BaseException e) {
        return AjaxResult.error(e.getMessage());
    }


}
